package com.extract.rar;

import net.sf.sevenzipjbinding.IInArchive;
import net.sf.sevenzipjbinding.SevenZip;
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;

import java.io.File;
import java.io.RandomAccessFile;

/**
 * 孙敬佳
 * 2023 \ 07 \ 26
 */

public class ExtractRAR {

    public static void uncompressAllFile(File newFile, String targetFilePath) throws Exception {
        RandomAccessFile randomAccessFile = null;
        IInArchive inArchive = null;
        // 第一个参数是需要解压的压缩包路径，第二个参数参考JdkAPI文档的RandomAccessFile
        randomAccessFile = new RandomAccessFile(newFile.getPath(), "r");
        inArchive = SevenZip.openInArchive(null, new RandomAccessFileInStream(randomAccessFile));
        int[] in = new int[inArchive.getNumberOfItems()];
        for (int i = 0; i < in.length; i++) {
            in[i] = i;
        }
//        inArchive.extract(in, true, new ExtractZipFileCallback(inArchive, targetFilePath));
        inArchive.extract(in, false, new ExtractCallback(inArchive, targetFilePath));
        System.out.println("解压完成");
    }

    public static void main(String[] args) {
        String s1 = "hello";
        String s2 = "world";
        int i = s1.compareTo(s2);
        System.out.println(i);
    }
}
